<template>
  <el-card class="box-card" style="margin:10px 0px">
    <div slot="header" class="clearfix" >
      <!-- v-model="activeName" @tab-click="handleClick" -->
      <!-- 左侧内容 -->
      <el-tabs class="tab" v-model="activeName">
        <el-tab-pane label="销售额" name="sale"></el-tab-pane>
        <el-tab-pane label="访问量" name="visit"></el-tab-pane>
      </el-tabs>
      <!-- 头部右侧内容 -->
      <div class="right">
        <span @click="setDay">今日</span>
        <span @click="setWeek">本周</span>
        <span @click="setMonth">本月</span>
        <span @click="setYear">本年</span>
        <el-date-picker v-model="date" type="datetimerange" range-separator="-" start-placeholder="开始日期"
        value-format="yyyy-MM-dd"
        format="yyyy-MM-dd"
          end-placeholder="结束日期" class="data" size="mini">
        </el-date-picker>
      </div>
    </div>
    <div>
      <el-row :gutter="10">
        <el-col :span="18">
          <div class="charts" ref="charts">
          </div>
        </el-col>
        <el-col :span="6">
          <div class="">
            <h4>门店{{title}}排名</h4>
            <ul>
              <li><span class="rindex">1</span><span class="rname">肯德基</span><span class="rvalue">323,234</span></li>
              <li><span class="rindex">2</span><span class="rname">麦当劳</span><span class="rvalue">299,132</span></li>
              <li><span class="rindex">3</span><span class="rname">海底捞</span><span class="rvalue">283,998</span></li>
              <li><span class="rindex">4</span><span class="rname">汉堡王</span></span><span class="rvalue">266.226</span></li>
              <li><span class="rindex">5</span><span class="rname">茶颜悦色</span><span class="rvalue">223,445</span></li>
              <li><span class="rindex">6</span><span class="rname">西贝筱面村</span><span class="rvalue">219,663</span></li>
              <li><span class="rindex">7</span><span class="rname">德克士</span><span class="rvalue">200,997</span></li>

            </ul>
          </div>
        </el-col>
      </el-row>
    </div>
  </el-card>
</template>

<script>
import * as echarts from 'echarts'
import dayjs from 'dayjs'
export default {
  mounted () {
    this.mycharts = echarts.init(this.$refs.charts);
    this.mycharts.setOption(
      {
        title: {
          text: this.title+'趋势'
        },
        // tooltip: {
        //   trigger: 'axis',
        //   axisPointer: {
        //     type: 'shadow'
        //   }
        // },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: [
          {
            type: 'category',
            data: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
            axisTick: {
              alignWithLabel: true
            }
          }
        ],
        yAxis: [
          {
            type: 'value'
          }
        ],
        series: [
          {
            name: 'Direct',
            type: 'bar',
            barWidth: '60%',
            data: [90, 180, 200, 334, 390, 330, 220, 150, 330, 280, 190, 150]
          }
        ]
      }
    )

  },
  name: 'Sale',
  data () {
    return {
      activeName: 'sale',
      mycharts:null,
      date:[],//日历选择器数据
    }
  },
  methods:{
    //本天
    setDay(){
        const day = dayjs().format('YYYY-MM-DD')
        this.date = [day,day]
    },
    //本月
    setWeek(){
        const start = dayjs().day(1).format('YYYY-MM-DD');
        const end = dayjs().day(7).format('YYYY-MM-DD');
        this.date = [start,end]
    },
    //本月
    setMonth(){
        const start = dayjs().startOf('month').format('YYYY-MM-DD')
        const end = dayjs().endOf('month').format('YYYY-MM-DD')
        this.date = [start,end]
    },
    //本年
    setYear(){
        const start = dayjs().startOf('year').format('YYYY-MM-DD')
        const end = dayjs().endOf('year').format('YYYY-MM-DD')
        this.date = [start,end]
    }
  },
  computed:{
    title(){
        return this.activeName== 'sale' ? '销售额':'访问量';
    }
  },
  //监听属性
  watch:{
    //重新修改图表配置
    title: function(){
        this.mycharts.setOption({
        title:{
            text:this.title+'趋势'
        }
    })
    }
  }
}
</script>

<style scoped>
.clearfix {
  position: relative;
  display: flex;
  justify-content: space-between;
}
.tab {
  width: 100%;
}
.right {
  position: absolute;
  right: 0;
}
.right span{
    cursor: pointer;
}
.data {
  width: 250px !important;
  margin: 0px 10px;
}
.right span {
  margin: 0px 10px;
}
.charts {
  width: 100%;
  height: 300px;
}
ul {
  list-style: none;
  width: 100%;
  height: 300px;
  padding: 0;
}
ul li {
  height: 12%;
}
ul :nth-child(1) .rindex,
ul :nth-child(2) .rindex,
ul :nth-child(3) .rindex {
  float: left;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: black;
  color: white;
  text-align: center;
}
ul :nth-child(n+4) .rindex {
  float: left;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  color: black;
  text-align: center;
}

.rvalue {
  float: right;
}
.rname {
  margin-left: 20px;
}
>>>canvas {
width:100%!important;
}

.charts >>>div {
    width: 100%!important;
}

>>>.el-card__header{
    border-bottom: none!important;
}

</style>